package com.xdb.logging;


public class Jdk14LogImpl implements Logger {

	private java.util.logging.Logger log;

	private int errorCount;
	private int warnCount;
	private int infoCount;
	private int debugCount;

	private String loggerName;

	public Jdk14LogImpl(String loggerName) {
		this.loggerName = loggerName;
		log = java.util.logging.Logger.getLogger(loggerName);
	}

	public boolean isDebugEnabled() {
		return log.isLoggable(java.util.logging.Level.FINE);
	}

	public void error(Object msg, Throwable e) {
		log.logp(java.util.logging.Level.SEVERE, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString(), e);
		errorCount++;
	}

	public void error(Object msg) {
		log.logp(java.util.logging.Level.SEVERE, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString());
		errorCount++;
	}

	public void debug(Object msg) {
		debugCount++;
		log.logp(java.util.logging.Level.FINE, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString());
	}

	public void debug(Object msg, Throwable e) {
		debugCount++;
		log.logp(java.util.logging.Level.FINE, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString(), e);
	}

	public void warn(Object msg) {
		log.logp(java.util.logging.Level.WARNING, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString());
		warnCount++;
	}

	@Override
	public void warn(Object msg, Throwable e) {
		log.logp(java.util.logging.Level.WARNING, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString(), e);
		warnCount++;
	}

	@Override
	public int getWarnCount() {
		return warnCount;
	}

	public int getErrorCount() {
		return errorCount;
	}

	@Override
	public void resetStat() {
		errorCount = 0;
		warnCount = 0;
		infoCount = 0;
		debugCount = 0;
	}

	@Override
	public boolean isInfoEnabled() {
		return log.isLoggable(java.util.logging.Level.INFO);
	}

	@Override
	public void info(Object msg) {
		log.logp(java.util.logging.Level.INFO, loggerName, Thread.currentThread().getStackTrace()[1].getMethodName(), msg == null ? "" : msg.toString());
		infoCount++;
	}

	@Override
	public int getInfoCount() {
		return infoCount;
	}

	@Override
	public boolean isWarnEnabled() {
		return log.isLoggable(java.util.logging.Level.WARNING);
	}

	public int getDebugCount() {
		return debugCount;
	}

}
